package ch14;

import java.util.Scanner;

/**
 * Created by zhangyunqi on 2017/10/15.
 */
public class Postfix {
    public static void main(String[] args) {
        String expression,again;
        int result;

        try {
            Scanner in = new Scanner ( System.in );
            do {
                PostfixEvaluator evaluator = new PostfixEvaluator();
                System.out.println ("Enter a valid postfix expression:");
                expression= in.nextLine ();


                if (expression != null && expression.matches("^[0.0-9.0]+$"))  {
                    System.out.println("输入是数字！");
                    double num = Double.parseDouble(expression);
                    System.out.println(num);
                } else {
                    System.out.println("输入值为字符！");
                }



                result=evaluator.evaluate(expression);
                System.out.println ();
                System.out.println ("That expression equals"+":  " +result);

                System.out.print ( "Evaluate another expression [Y/N]" );
                again=in.nextLine ();
                System.out.println ();

            }
            while ( again.equalsIgnoreCase ( "y" ));

        }

        catch (Exception IOException){
            System.out.println ("Input exception reported");
        }
    }
}
